<!--
 * @Author: ybf
 * @Date: 2023-02-21 15:31:51
 * @LastEditTime: 2023-02-22 10:43:19
 * @Description: 描述
 * Copyright (c) 2023 by 慧能分享, All Rights Reserved.
-->
<template>
    <div class="timing">
        <nu-col :span="24" style="height:calc(100% - 20px);">
            <!-- <nutbTitle title="系统对时"></nutbTitle> -->
            <NuVerifyForm :inline="false" :model="formData" ref="formData" label-width="100px" class="searchForm"
                @searchForm="searchForm" :buttons="fyButtons">
                <NuformItem label="当前系统时间：" prop="" width="auto">
                    <span class="time">{{ currentTime }}</span>
                </NuformItem>
                <NuformItem label="对时标准：" prop="timeStandard" :rules="[{ required: false, message: '对时标准不能为空' }]"
                    width="320px">
                    <nu-select class="searchSelect" :filterable="true" :list="typeList" type="text"
                    v-model="formData.timeStandard" autocomplete="off" @change="timeStandardChange"
                        style="width: 100%;">
                    </nu-select>
                </NuformItem>
                <NuformItem label="对时时间：" prop="" width="auto">
                    <span class="time">{{ timingTime }}</span>
                    <!-- <el-date-picker v-model="formData.timingTime" type="datetime" placeholder="选择日期时间" class="time">
                                    </el-date-picker> -->
            </NuformItem>
            <NuformItem>
                <nu-button type="primary" class="searchButton" @click="searchTable">立即同步</nu-button>
                <!-- <nu-button type="primary" class="searchButton" @click="addTable">应用</nu-button> -->
            </NuformItem>
        </NuVerifyForm>
            <!-- <div class="remark">
                    NTP (Network Time Protocol，网络时间协议）是用来使计算机时间同步的一种协议。
                    它可以使计算机对其服务器或时钟源做同步化，它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒，WAN上几十毫秒)。
                    对于服务器群集来说，这个是一个很重要的服务，因为群集需要保证每个服务器的时间是保持一致的，
                    这样它们在执行同一个任务时才不会出现有的服务器有滞后的现象，这样群集的状态才是健康的。
                    <br />GPS时，也称GPS time，GPST，由GPS星载原子钟和地面监控站原子钟组成的一种原子时基准，与国际原子时保持有19s的常数差，并在GPS标准历元1980年1月6日零时与UTC保持一致
                </div> -->
        </nu-col>
    </div>
</template>
    
<script>
import nuCol from "@/components/base/col.vue"
import nutbTitle from "@/components/base/tableTitle.vue"
import NuVerifyForm from "@/components/verify-form"
import NuformItem from "@/components/verify-form/form-item.vue"
import nuInput from "@/components/base/input"
import nuSelect from "@/components/base/select"
import nuButton from "@/components/base/button"
import NuTableList from "@/components/tableList/TableFormList"
import nuDialog from "@/components/base/dialog"

import { getToken } from "@/utils/auth";
import { getDateTime, getWeekDate } from "@/utils/ruoyi";
export default {
    name: "timing",
    components: { nuCol, nutbTitle, NuVerifyForm, NuformItem, nuInput, nuSelect, nuButton, NuTableList, nuDialog },
    data() {
        return {
            formData: { timeStandard: 2 },
            fyButtons: [],
            typeList: [{ label: 'NTP对时', value: 1 }, { label: 'GPS装置对时', value: 2 }],
            currentTime: '2021年 01月 03日 星期日 17:12:30 CST',
            timingTime: '2021年 01月 03日 星期日 17:12:30 CST',
            timeInterval: null
        };
    },
    computed: {},
    created() { },
    mounted() {
        this.getCurrentTime();
        this.getTimingTime()
        this.timeInterval = setInterval(() => {
            this.getCurrentTime();
            this.getTimingTime()
        }, 500)
    },
    beforeDestroy() {
        if (this.timeInterval) {
            clearInterval(this.timeInterval)
        }
    },
    methods: {
        /**
         * 查询
         */
        searchTable() {
            this.$refs['formData'].searchForm('form');
        },
        /**
         * form组件内置事件
         */
        searchForm(val) {
            if (val) {
                this.editAlarmType();
            }
        },
        /**
         * 对时标准change
         */
        timeStandardChange() { },
        /**
         * 获取系统时间
         */
        getCurrentTime() {
            let o = getDateTime('obj')
            let week = getWeekDate()
            this.currentTime = `${o.year}年 ${o.month}月 ${o.curDate}日 ${week} ${o.curHours}:${o.curMinutes}:${o.curSeconds} CST`
            // this.$httpGet(window.api.getCurrentTime).then(res => {
            //     if (res.success && res.data) {
            //     } else {
            //     }
            // }).catch(err => { });
        },
        /**
         * 获取对时时间
         */
        getTimingTime() {
            let o = getDateTime('obj')
            let week = getWeekDate()
            this.timingTime = `${o.year}年 ${o.month}月 ${o.curDate}日 ${week} ${o.curHours}:${o.curMinutes}:${o.curSeconds} CST`
            // this.$httpGet(window.api.getCurrentTime, {...this.formData}).then(res => {
            //     if (res.success && res.data) {
            //     } else {
            //     }
            // }).catch(err => { });
        },
        /**
         * 立即同步
         */
        editAlarmType() {
            let postData = {
                ...this.formData,
            };
            for (let k in postData.query) {
                if (postData.query[k] && Object.prototype.toString.call(postData.query[k]) == '[object String]') {
                    postData.query[k] = postData.query[k].toString().trim();
                }
            }
            this.$httpPost(window.api.editAlarmType, postData).then(res => {
                if (res.success) {
                    this.$message({
                        message: '同步1成功',
                        type: 'success'
                    })
                    this.getCurrentTime()
                } else {
                }
            }).catch(err => {

            });
        },
    }
};
</script>
    
<style scoped lang="scss">
.timing {
    height: 100%;
}

.searchForm {
    // height: calc(100% - 40px);
    display: flex;
    flex-direction: column;
    // align-items: center;
    position: relative;
    padding: 40px;
    align-items: center;
    margin-top: 14%;
}

.submitForm {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}

.time {
    line-height: 40px;
}

.remark {
    padding: 8px 40px;
    font-size: 14px;
    line-height: 24px;
}
</style>